home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 June / MacFormat 25.iso / Shareware City / Developers / OutOfPhase1.1 Source / OutOfPhase Folder / EffectSpecList.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-04  |  9.6 KB  |  312 lines  |  [TEXT/KAHL]

  1. /* EffectSpecList.c */
  2. /*****************************************************************************/
  3. /*                                                                           */
  4. /*    Out Of Phase:  Digital Music Synthesis on General Purpose Computers    */
  5. /*    Copyright (C) 1994  Thomas R. Lawrence                                 */
  6. /*                                                                           */
  7. /*    This program is free software; you can redistribute it and/or modify   */
  8. /*    it under the terms of the GNU General Public License as published by   */
  9. /*    the Free Software Foundation; either version 2 of the License, or      */
  10. /*    (at your option) any later version.                                    */
  11. /*                                                                           */
  12. /*    This program is distributed in the hope that it will be useful,        */
  13. /*    but WITHOUT ANY WARRANTY; without even the implied warranty of         */
  14. /*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          */
  15. /*    GNU General Public License for more details.                           */
  16. /*                                                                           */
  17. /*    You should have received a copy of the GNU General Public License      */
  18. /*    along with this program; if not, write to the Free Software            */
  19. /*    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.              */
  20. /*                                                                           */
  21. /*    Thomas R. Lawrence can be reached at tomlaw@world.std.com.             */
  22. /*                                                                           */
  23. /*****************************************************************************/
  24.  
  25. #include "MiscInfo.h"
  26. #include "Audit.h"
  27. #include "Debug.h"
  28. #include "Definitions.h"
  29.  
  30. #include "EffectSpecList.h"
  31. #include "Memory.h"
  32. #include "Array.h"
  33. #include "DelayEffectSpec.h"
  34. #include "NonlinearProcSpec.h"
  35. #include "FilterSpec.h"
  36. #include "AnalyzerSpec.h"
  37.  
  38.  
  39. typedef struct
  40.     {
  41.         EffectTypes                Type;
  42.         union
  43.             {
  44.                 struct DelayEffectRec*        DelayEffectSpec;
  45.                 struct NonlinProcSpecRec*    NLProcEffectSpec;
  46.                 struct FilterSpecRec*            FilterEffectSpec;
  47.                 struct AnalyzerSpecRec*        AnalyzerEffectSpec;
  48.             } u;
  49.     } EffectNodeRec;
  50.  
  51.  
  52. struct EffectSpecListRec
  53.     {
  54.         ArrayRec*                    List;
  55.     };
  56.  
  57.  
  58. /* create a new effect list */
  59. EffectSpecListRec*    NewEffectSpecList(void)
  60.     {
  61.         EffectSpecListRec*    EffectSpecList;
  62.  
  63.         EffectSpecList = (EffectSpecListRec*)AllocPtrCanFail(sizeof(EffectSpecListRec),
  64.             "EffectSpecListRec");
  65.         if (EffectSpecList == NIL)
  66.             {
  67.              FailurePoint1:
  68.                 return NIL;
  69.             }
  70.         EffectSpecList->List = NewArray();
  71.         if (EffectSpecList->List == NIL)
  72.             {
  73.              FailurePoint2:
  74.                 ReleasePtr((char*)EffectSpecList);
  75.                 goto FailurePoint1;
  76.             }
  77.         return EffectSpecList;
  78.     }
  79.  
  80.  
  81. /* dispose of an effect list */
  82. void                                DisposeEffectSpecList(EffectSpecListRec* EffectSpecList)
  83.     {
  84.         long                            Scan;
  85.         long                            Limit;
  86.  
  87.         CheckPtrExistence(EffectSpecList);
  88.         Limit = GetEffectSpecListLength(EffectSpecList);
  89.         for (Scan = 0; Scan < Limit; Scan += 1)
  90.             {
  91.                 EffectNodeRec*        OneEffect;
  92.  
  93.                 OneEffect = (EffectNodeRec*)ArrayGetElement(EffectSpecList->List,Scan);
  94.                 CheckPtrExistence(OneEffect);
  95.                 switch (OneEffect->Type)
  96.                     {
  97.                         default:
  98.                             EXECUTE(PRERR(ForceAbort,"DisposeEffectSpecList:  unknown effect type"));
  99.                             break;
  100.                         case eDelayEffect:
  101.                             DisposeDelayLineSpec(OneEffect->u.DelayEffectSpec);
  102.                             break;
  103.                         case eNLProcEffect:
  104.                             DisposeNonlinProcSpec(OneEffect->u.NLProcEffectSpec);
  105.                             break;
  106.                         case eFilterEffect:
  107.                             DisposeFilterSpec(OneEffect->u.FilterEffectSpec);
  108.                             break;
  109.                         case eAnalyzerEffect:
  110.                             DisposeAnalyzerSpec(OneEffect->u.AnalyzerEffectSpec);
  111.                             break;
  112.                     }
  113.                 ReleasePtr((char*)OneEffect);
  114.             }
  115.         DisposeArray(EffectSpecList->List);
  116.         ReleasePtr((char*)EffectSpecList);
  117.     }
  118.  
  119.  
  120. /* add a delay effect to the spec list */
  121. MyBoolean                        AddDelayToEffectSpecList(EffectSpecListRec* EffectSpecList,
  122.                                             struct DelayEffectRec* DelaySpec)
  123.     {
  124.         EffectNodeRec*        Effect;
  125.  
  126.         CheckPtrExistence(EffectSpecList);
  127.         CheckPtrExistence(DelaySpec);
  128.         Effect = (EffectNodeRec*)AllocPtrCanFail(sizeof(EffectNodeRec),"EffectNodeRec");
  129.         if (Effect == NIL)
  130.             {
  131.              FailurePoint1:
  132.                 return False;
  133.             }
  134.         Effect->Type = eDelayEffect;
  135.         Effect->u.DelayEffectSpec = DelaySpec;
  136.         if (!ArrayAppendElement(EffectSpecList->List,Effect))
  137.             {
  138.              FailurePoint2:
  139.                 ReleasePtr((char*)Effect);
  140.                 goto FailurePoint1;
  141.             }
  142.         return True;
  143.     }
  144.  
  145.  
  146. /* add a nonlinear processor to the spec list */
  147. MyBoolean                        AddNLProcToEffectSpecList(EffectSpecListRec* EffectSpecList,
  148.                                             struct NonlinProcSpecRec* NLProcSpec)
  149.     {
  150.         EffectNodeRec*        Effect;
  151.  
  152.         CheckPtrExistence(EffectSpecList);
  153.         CheckPtrExistence(NLProcSpec);
  154.         Effect = (EffectNodeRec*)AllocPtrCanFail(sizeof(EffectNodeRec),"EffectNodeRec");
  155.         if (Effect == NIL)
  156.             {
  157.              FailurePoint1:
  158.                 return False;
  159.             }
  160.         Effect->Type = eNLProcEffect;
  161.         Effect->u.NLProcEffectSpec = NLProcSpec;
  162.         if (!ArrayAppendElement(EffectSpecList->List,Effect))
  163.             {
  164.              FailurePoint2:
  165.                 ReleasePtr((char*)Effect);
  166.                 goto FailurePoint1;
  167.             }
  168.         return True;
  169.     }
  170.  
  171.  
  172. /* add a parallel filter array to the spec list */
  173. MyBoolean                        AddFilterToEffectSpecList(EffectSpecListRec* EffectSpecList,
  174.                                             struct FilterSpecRec* FilterSpec)
  175.     {
  176.         EffectNodeRec*        Effect;
  177.  
  178.         CheckPtrExistence(EffectSpecList);
  179.         CheckPtrExistence(FilterSpec);
  180.         Effect = (EffectNodeRec*)AllocPtrCanFail(sizeof(EffectNodeRec),"EffectNodeRec");
  181.         if (Effect == NIL)
  182.             {
  183.              FailurePoint1:
  184.                 return False;
  185.             }
  186.         Effect->Type = eFilterEffect;
  187.         Effect->u.FilterEffectSpec = FilterSpec;
  188.         if (!ArrayAppendElement(EffectSpecList->List,Effect))
  189.             {
  190.              FailurePoint2:
  191.                 ReleasePtr((char*)Effect);
  192.                 goto FailurePoint1;
  193.             }
  194.         return True;
  195.     }
  196.  
  197.  
  198. /* add an analyzer to the spec list */
  199. MyBoolean                        AddAnalyzerToEffectSpecList(EffectSpecListRec* EffectSpecList,
  200.                                             struct AnalyzerSpecRec* AnalyzerSpec)
  201.     {
  202.         EffectNodeRec*        Effect;
  203.  
  204.         CheckPtrExistence(EffectSpecList);
  205.         CheckPtrExistence(AnalyzerSpec);
  206.         Effect = (EffectNodeRec*)AllocPtrCanFail(sizeof(EffectNodeRec),"EffectNodeRec");
  207.         if (Effect == NIL)
  208.             {
  209.              FailurePoint1:
  210.                 return False;
  211.             }
  212.         Effect->Type = eAnalyzerEffect;
  213.         Effect->u.AnalyzerEffectSpec = AnalyzerSpec;
  214.         if (!ArrayAppendElement(EffectSpecList->List,Effect))
  215.             {
  216.              FailurePoint2:
  217.                 ReleasePtr((char*)Effect);
  218.                 goto FailurePoint1;
  219.             }
  220.         return True;
  221.     }
  222.  
  223.  
  224. /* find out how many effects are in the list */
  225. long                                GetEffectSpecListLength(EffectSpecListRec* EffectSpecList)
  226.     {
  227.         CheckPtrExistence(EffectSpecList);
  228.         return ArrayGetLength(EffectSpecList->List);
  229.     }
  230.  
  231.  
  232. /* get the type of the specified effect */
  233. EffectTypes                    GetEffectSpecListElementType(EffectSpecListRec* EffectSpecList,
  234.                                             long Index)
  235.     {
  236.         EffectNodeRec*        Effect;
  237.  
  238.         CheckPtrExistence(EffectSpecList);
  239.         ERROR((Index < 0) || (Index >= GetEffectSpecListLength(EffectSpecList)),
  240.             PRERR(ForceAbort,"GetEffectSpecListElementType:  index out of range"));
  241.         Effect = (EffectNodeRec*)ArrayGetElement(EffectSpecList->List,Index);
  242.         CheckPtrExistence(Effect);
  243.         return Effect->Type;
  244.     }
  245.  
  246.  
  247. /* get the delay effect at the specified index */
  248. struct DelayEffectRec*    GetDelayEffectFromEffectSpecList(
  249.                                             EffectSpecListRec* EffectSpecList, long Index)
  250.     {
  251.         EffectNodeRec*        Effect;
  252.  
  253.         CheckPtrExistence(EffectSpecList);
  254.         ERROR((Index < 0) || (Index >= GetEffectSpecListLength(EffectSpecList)),
  255.             PRERR(ForceAbort,"GetDelayEffectFromEffectSpecList:  index out of range"));
  256.         Effect = (EffectNodeRec*)ArrayGetElement(EffectSpecList->List,Index);
  257.         CheckPtrExistence(Effect);
  258.         ERROR(Effect->Type != eDelayEffect,PRERR(ForceAbort,
  259.             "GetDelayEffectFromEffectSpecList:  effect isn't a delay"));
  260.         return Effect->u.DelayEffectSpec;
  261.     }
  262.  
  263.  
  264. /* get the nonlinear processor from the specified index */
  265. struct NonlinProcSpecRec*    GetNLProcEffectFromEffectSpecList(
  266.                                             EffectSpecListRec* EffectSpecList, long Index)
  267.     {
  268.         EffectNodeRec*        Effect;
  269.  
  270.         CheckPtrExistence(EffectSpecList);
  271.         ERROR((Index < 0) || (Index >= GetEffectSpecListLength(EffectSpecList)),
  272.             PRERR(ForceAbort,"GetNLProcEffectFromEffectSpecList:  index out of range"));
  273.         Effect = (EffectNodeRec*)ArrayGetElement(EffectSpecList->List,Index);
  274.         CheckPtrExistence(Effect);
  275.         ERROR(Effect->Type != eNLProcEffect,PRERR(ForceAbort,
  276.             "GetNLProcEffectFromEffectSpecList:  effect isn't a nonlinear processor"));
  277.         return Effect->u.NLProcEffectSpec;
  278.     }
  279.  
  280.  
  281. /* get the filter from the specified index */
  282. struct FilterSpecRec*    GetFilterEffectFromEffectSpecList(
  283.                                             EffectSpecListRec* EffectSpecList, long Index)
  284.     {
  285.         EffectNodeRec*        Effect;
  286.  
  287.         CheckPtrExistence(EffectSpecList);
  288.         ERROR((Index < 0) || (Index >= GetEffectSpecListLength(EffectSpecList)),
  289.             PRERR(ForceAbort,"GetFilterEffectFromEffectSpecList:  index out of range"));
  290.         Effect = (EffectNodeRec*)ArrayGetElement(EffectSpecList->List,Index);
  291.         CheckPtrExistence(Effect);
  292.         ERROR(Effect->Type != eFilterEffect,PRERR(ForceAbort,
  293.             "GetFilterEffectFromEffectSpecList:  effect isn't a filter"));
  294.         return Effect->u.FilterEffectSpec;
  295.     }
  296.  
  297.  
  298. struct AnalyzerSpecRec*    GetAnalyzerEffectFromEffectSpecList(
  299.                                             EffectSpecListRec* EffectSpecList, long Index)
  300.     {
  301.         EffectNodeRec*        Effect;
  302.  
  303.         CheckPtrExistence(EffectSpecList);
  304.         ERROR((Index < 0) || (Index >= GetEffectSpecListLength(EffectSpecList)),
  305.             PRERR(ForceAbort,"GetAnalyzerEffectFromEffectSpecList:  index out of range"));
  306.         Effect = (EffectNodeRec*)ArrayGetElement(EffectSpecList->List,Index);
  307.         CheckPtrExistence(Effect);
  308.         ERROR(Effect->Type != eAnalyzerEffect,PRERR(ForceAbort,
  309.             "GetAnalyzerEffectFromEffectSpecList:  effect isn't a analyzer"));
  310.         return Effect->u.AnalyzerEffectSpec;
  311.     }
  312.